/**
 * 类：教室
 */

public class Classroom {
    public static Student[] students;

    Classroom(int studentNum) {
        students = new Student[studentNum];
        for (int i = 0; i < studentNum; i++) {
            students[i] = new Student();
            students[i].id = i;
            students[i].score = Math.random() * 100;
            students[i].state = (int) (Math.random() * 6 + 1);
            students[i].getInfo();
        }
    }

    public void printStudents(int state) {
        for (Student student : students) {
            if (state == student.getState() || state > 6 || state < 1) {
                student.getInfo();
            }
        }
    }

    public void sortStudents() {
        //实际上是交换地址
        Student tmp;
        for (int i = 0; i < students.length - 1; i++) { //遍历 students.length次
            for (int j = 0; j < students.length - i - 1; j++) { //冒泡之后的数字，不需要再比较
                if (students[j + 1].score > students[j].score) {
                    tmp = students[j + 1];
                    students[j + 1] = students[j];
                    students[j] = tmp;
                }
            }
        }
        System.out.println("Sort done!");
    }
}
